<?php

require_once 'DatabaseConnectionTest.php';
require_once 'GrosseryListTest.php';
require_once 'UserTest.php';
require_once 'ProductTest.php';
require_once 'TagTest.php';

/**
 * This class represents a tester.
 * Construct all existing tests and executes them
 * @author Denis
 * @version 1.0
 */
class Tester {
	
	public $databaseConnectionTest;
	private $grosseryListTest;
	private $userTest;
	private $productTest;
	private $tagTest;
	private $create = false;
	
	public function __construct(){
		$this->databaseConnectionTest = new DatabaseConnectionsTest();
		$this->grosseryListTest = new GrosseryListTest();
		$this->userTest = new UserTest();
		$this->productTest = new ProductTest();
		$this->tagTest = new TagTest();
		$this->test();
	}
	
	/**
	 * Execute all the tests
	 */
	public function test(){
		$bool = true;
		if(!$this->databaseConnectionTest->testDatabaseConnection()){
			print 'Database connection test failed</br>';
			$bool = false;
		}
		else{
			print 'Database connection test OK</br>';
		}
		if(!$this->grosseryListTest->TestReadGrosseryList()){
			print 'Grocerylist read failed</br>';
			$bool = false;
		}
		else{
			print 'Grocerylist read OK</br>';
		}
		//Test Grosserylist create. Is only executed if create is true.
		if($this->create){
			if(!$this->grosseryListTest->testCreateGrosseryList()){
				print 'Grocerylist create failed</br>';
				$bool = false;
			}
			else{
				print 'Grocerylist create OK</br>';
			}
		}
		if(!$this->userTest->testReadUser()){
			print 'User read failed</br>';
			$bool = false;
		}
		else{
			print 'User read OK</br>';
		}
		if(!$this->productTest->testGetAllProduct()){
			print 'Get all products failed</br>';
			$bool = false;
		}
		else{
			print 'Get all products OK</br>';
		}
		if(!$this->tagTest->testToArray()){
			print 'Tag method to array failed</br>';
			$bool = false;
		}
		else{
			print 'Tag method toArray OK</br>';
		}
		$this->productTest->testGetProductByTagsCommand();
		if($bool){
			print ('OK</br>');
		}
		else{
			print ('FAIL</br>');
		}
	}
}